package com.ruoyi.partybuilding.common;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.annotation.Priority;
import javax.servlet.http.HttpServletRequest;


@Priority(1)
@RestControllerAdvice
@Slf4j
@Data
public class ClientTipsException extends   RuntimeException {
    private int code;
    private String msg;
    public ClientTipsException(){super("");}
    public ClientTipsException(String msg){super(msg);}
    public static ClientTipsException bad(String msg){

        var exp=new ClientTipsException(msg);
        exp.code= R.BAD;
        exp.msg=msg;
        return exp;
    }
    public static ClientTipsException fail(String msg){
        var exp=new ClientTipsException(msg);
        exp.code= R.FAIL;
        exp.msg=msg;
        return exp;
    }

    @ExceptionHandler(ClientTipsException.class)
    public R handleTipsException(ClientTipsException e, HttpServletRequest request) {
        var r = new R<>();
        r.setMsg(e.getMsg());
        r.setCode(e.code);
        return r;
    }
}
